| Fully Qualified Name: | CodeIgniter\Router\RouteCollection |
| Implements: | RouteCollectionInterface |
Class RouteCollection
| Name | Description | Defined By |
|---|---|---|
| __construct() | Constructor | RouteCollection |
| add() | Adds a single route to the collection. | RouteCollection |
| addPlaceholder() | Registers a new constraint with the system. Constraints are used by the routes as placeholders for regular expressions to make defining the routes more human-friendly. | RouteCollection |
| addRedirect() | Adds a temporary redirect from one route to another. Used for redirecting traffic from old, non-existing routes to the new moved routes. | RouteCollection |
| cli() | Specifies a route that is only available to command-line requests. | RouteCollection |
| delete() | Specifies a route that is only available to DELETE requests. | RouteCollection |
| environment() | Limits the routes to a specified ENVIRONMENT or they won't run. | RouteCollection |
| get() | Specifies a route that is only available to GET requests. | RouteCollection |
| get404Override() | Returns the 404 Override setting, which can be null, a closure or the controller/string. | RouteCollection |
| getDefaultController() | Returns the name of the default controller. With Namespace. | RouteCollection |
| getDefaultMethod() | Returns the name of the default method to use within the controller. | RouteCollection |
| getDefaultNamespace() | Returns the default namespace as set in the Routes config file. | RouteCollection |
| getFilterForRoute() | Returns the filter that should be applied for a single route, along with any parameters it might have. Parameters are found by splitting the parameter name on a colon to separate the filter name from the parameter list, and the splitting the result on commas. So: | RouteCollection |
| getHTTPVerb() | Returns the current HTTP Verb being used. | RouteCollection |
| getRedirectCode() | Grabs the HTTP status code from a redirecting Route. | RouteCollection |
| getRoutes() | Returns the raw array of available routes. | RouteCollection |
| getRoutesOptions() | Returns one or all routes options | RouteCollection |
| group() | Group a series of routes under a single URL segment. This is handy for grouping items into an admin area, like: | RouteCollection |
| head() | Specifies a route that is only available to HEAD requests. | RouteCollection |
| isFiltered() | Checks a route (using the "from") to see if it's filtered or not. | RouteCollection |
| isRedirect() | Determines if the route is a redirecting route. | RouteCollection |
| map() | A shortcut method to add a number of routes at a single time. | RouteCollection |
| match() | Specifies a single route to match for multiple HTTP Verbs. | RouteCollection |
| options() | Specifies a route that is only available to OPTIONS requests. | RouteCollection |
| patch() | Specifies a route that is only available to PATCH requests. | RouteCollection |
| post() | Specifies a route that is only available to POST requests. | RouteCollection |
| presenter() | Creates a collections of HTTP-verb based routes for a presenter controller. | RouteCollection |
| put() | Specifies a route that is only available to PUT requests. | RouteCollection |
| resetRoutes() | Reset the routes, so that a FeatureTestCase can provide the explicit ones needed for it. | RouteCollection |
| resource() | Creates a collections of HTTP-verb based routes for a controller. | RouteCollection |
| reverseRoute() | Attempts to look up a route based on it's destination. | RouteCollection |
| set404Override() | Sets the class/method that should be called if routing doesn't find a match. It can be either a closure or the controller/method name exactly like a route is defined: Users::index | RouteCollection |
| setAutoRoute() | If TRUE, the system will attempt to match the URI against Controllers by matching each segment against folders/files in APPPATH/Controllers, when a match wasn't found against defined routes. | RouteCollection |
| setDefaultConstraint() | Sets the default constraint to be used in the system. Typically for use with the 'resource' method. | RouteCollection |
| setDefaultController() | Sets the default controller to use when no other controller has been specified. | RouteCollection |
| setDefaultMethod() | Sets the default method to call on the controller when no other method has been set in the route. | RouteCollection |
| setDefaultNamespace() | Sets the default namespace to use for Controllers when no other namespace has been specified. | RouteCollection |
| setHTTPVerb() | Sets the current HTTP verb. | RouteCollection |
| setTranslateURIDashes() | Tells the system whether to convert dashes in URI strings into underscores. In some search engines, including Google, dashes create more meaning and make it easier for the search engine to find words and meaning in the URI for better SEO. But it doesn't work well with PHP method names. | RouteCollection |
| shouldAutoRoute() | Returns the flag that tells whether to autoRoute URI against Controllers. | RouteCollection |
| shouldTranslateURIDashes() | Returns the current value of the translateURIDashes setting. | RouteCollection |
Constructor
| Parameter Name | Type | Description |
|---|---|---|
| $locator | \FileLocator | |
| $moduleConfig | \Config\Modules |
Returns:
Adds a single route to the collection.
Example: $routes->add('news', 'Posts::index');
| Parameter Name | Type | Description |
|---|---|---|
| $from | string | |
| $to | array|string | |
| $options | array |
Returns: \RouteCollectionInterface
Registers a new constraint with the system. Constraints are used by the routes as placeholders for regular expressions to make defining the routes more human-friendly.
You can pass an associative array as $placeholder, and have multiple placeholders added at once.
| Parameter Name | Type | Description |
|---|---|---|
| $placeholder | string|array | |
| $pattern | string |
Returns: \CodeIgniter\Router\RouteCollectionInterface
Adds a temporary redirect from one route to another. Used for redirecting traffic from old, non-existing routes to the new moved routes.
| Parameter Name | Type | Description |
|---|---|---|
| $from | string | The |
| $to | string | Either |
| $status | int | The |
Returns: \RouteCollection
Specifies a route that is only available to command-line requests.
| Parameter Name | Type | Description |
|---|---|---|
| $from | string | |
| $to | string|array | |
| $options | array |
Returns: \CodeIgniter\Router\RouteCollectionInterface
Specifies a route that is only available to DELETE requests.
| Parameter Name | Type | Description |
|---|---|---|
| $from | string | |
| $to | string|array | |
| $options | array |
Returns: \CodeIgniter\Router\RouteCollectionInterface
Limits the routes to a specified ENVIRONMENT or they won't run.
| Parameter Name | Type | Description |
|---|---|---|
| $env | string | |
| $callback | \Closure |
Returns: \RouteCollectionInterface
Specifies a route that is only available to GET requests.
| Parameter Name | Type | Description |
|---|---|---|
| $from | string | |
| $to | string|array | |
| $options | array |
Returns: \CodeIgniter\Router\RouteCollectionInterface
Returns the 404 Override setting, which can be null, a closure or the controller/string.
Returns: string|\Closure|null
Returns the name of the default controller. With Namespace.
Returns: string
Returns the name of the default method to use within the controller.
Returns: string
Returns the default namespace as set in the Routes config file.
Returns: string
Returns the filter that should be applied for a single route, along with any parameters it might have. Parameters are found by splitting the parameter name on a colon to separate the filter name from the parameter list, and the splitting the result on commas. So:
'role:admin,manager'
has a filter of "role", with parameters of ['admin', 'manager'].
| Parameter Name | Type | Description |
|---|---|---|
| $search | string |
Returns: string
Returns the current HTTP Verb being used.
Returns: string
Grabs the HTTP status code from a redirecting Route.
| Parameter Name | Type | Description |
|---|---|---|
| $from | string |
Returns: int
Returns the raw array of available routes.
| Parameter Name | Type | Description |
|---|---|---|
| $verb | mixed |
Returns: array
Returns one or all routes options
| Parameter Name | Type | Description |
|---|---|---|
| $from | string |
Returns: array
Group a series of routes under a single URL segment. This is handy for grouping items into an admin area, like:
Example: // Creates route: admin/users $route->group('admin', function() {
$route->resource('users');
});
| Parameter Name | Type | Description |
|---|---|---|
| $name | string | The |
| $params | ||
| $params |
Returns: void
Specifies a route that is only available to HEAD requests.
| Parameter Name | Type | Description |
|---|---|---|
| $from | string | |
| $to | string|array | |
| $options | array |
Returns: \CodeIgniter\Router\RouteCollectionInterface
Checks a route (using the "from") to see if it's filtered or not.
| Parameter Name | Type | Description |
|---|---|---|
| $search | string |
Returns: bool
Determines if the route is a redirecting route.
| Parameter Name | Type | Description |
|---|---|---|
| $from | string |
Returns: bool
A shortcut method to add a number of routes at a single time.
It does not allow any options to be set on the route, or to define the method used.
| Parameter Name | Type | Description |
|---|---|---|
| $routes | array | |
| $options | array |
Returns: \RouteCollectionInterface
Specifies a single route to match for multiple HTTP Verbs.
Example: $route->match( ['get', 'post'], 'users/(:num)', 'users/$1);
| Parameter Name | Type | Description |
|---|---|---|
| $verbs | array | |
| $from | string | |
| $to | string|array | |
| $options | array |
Returns: \CodeIgniter\Router\RouteCollectionInterface
Specifies a route that is only available to OPTIONS requests.
| Parameter Name | Type | Description |
|---|---|---|
| $from | string | |
| $to | string|array | |
| $options | array |
Returns: \CodeIgniter\Router\RouteCollectionInterface
Specifies a route that is only available to PATCH requests.
| Parameter Name | Type | Description |
|---|---|---|
| $from | string | |
| $to | string|array | |
| $options | array |
Returns: \CodeIgniter\Router\RouteCollectionInterface
Specifies a route that is only available to POST requests.
| Parameter Name | Type | Description |
|---|---|---|
| $from | string | |
| $to | string|array | |
| $options | array |
Returns: \CodeIgniter\Router\RouteCollectionInterface
Creates a collections of HTTP-verb based routes for a presenter controller.
Possible Options:
'controller' - Customize the name of the controller used in the 'to' route
'placeholder' - The regex used by the Router. Defaults to '(:any)'
Example:
$route->presenter('photos');
// Generates the following routes:
HTTP Verb | Path | Action | Used for...
----------+-------------+---------------+-----------------
GET /photos index showing all array of photo objects
GET /photos/show/{id} show showing a specific photo object, all properties
GET /photos/new new showing a form for an empty photo object, with default properties
POST /photos/create create processing the form for a new photo
GET /photos/edit/{id} edit show an editing form for a specific photo object, editable properties
POST /photos/update/{id} update process the editing form data
GET /photos/remove/{id} remove show a form to confirm deletion of a specific photo object
POST /photos/delete/{id} delete deleting the specified photo object
| Parameter Name | Type | Description |
|---|---|---|
| $name | string | The |
| $options | array | An |
Returns: \RouteCollectionInterface
Specifies a route that is only available to PUT requests.
| Parameter Name | Type | Description |
|---|---|---|
| $from | string | |
| $to | string|array | |
| $options | array |
Returns: \CodeIgniter\Router\RouteCollectionInterface
Reset the routes, so that a FeatureTestCase can provide the explicit ones needed for it.
Returns:
Creates a collections of HTTP-verb based routes for a controller.
Possible Options:
'controller' - Customize the name of the controller used in the 'to' route
'placeholder' - The regex used by the Router. Defaults to '(:any)'
'websafe' - - '1' if only GET and POST HTTP verbs are supported
Example:
$route->resource('photos');
// Generates the following routes:
HTTP Verb | Path | Action | Used for...
----------+-------------+---------------+-----------------
GET /photos index an array of photo objects
GET /photos/new new an empty photo object, with default properties
GET /photos/{id}/edit edit a specific photo object, editable properties
GET /photos/{id} show a specific photo object, all properties
POST /photos create a new photo object, to add to the resource
DELETE /photos/{id} delete deletes the specified photo object
PUT/PATCH /photos/{id} update replacement properties for existing photo
If 'websafe' option is present, the following paths are also available:
POST /photos/{id}/delete delete
POST /photos/{id} update
| Parameter Name | Type | Description |
|---|---|---|
| $name | string | The |
| $options | array | An |
Returns: \RouteCollectionInterface
Attempts to look up a route based on it's destination.
If a route exists:
'path/(:any)/(:any)' => 'Controller::method/$1/$2'
This method allows you to know the Controller and method and get the route that leads to it.
// Equals 'path/$param1/$param2'
reverseRoute('Controller::method', $param1, $param2);
| Parameter Name | Type | Description |
|---|---|---|
| $search | string | |
| ...$params | array | |
| $params |
Returns: string|bool
Sets the class/method that should be called if routing doesn't find a match. It can be either a closure or the controller/method name exactly like a route is defined: Users::index
This setting is passed to the Router class and handled there.
| Parameter Name | Type | Description |
|---|---|---|
| $callable | callable|null |
Returns: \RouteCollectionInterface
If TRUE, the system will attempt to match the URI against Controllers by matching each segment against folders/files in APPPATH/Controllers, when a match wasn't found against defined routes.
If FALSE, will stop searching and do NO automatic routing.
| Parameter Name | Type | Description |
|---|---|---|
| $value | bool |
Returns: \RouteCollectionInterface
Sets the default constraint to be used in the system. Typically for use with the 'resource' method.
| Parameter Name | Type | Description |
|---|---|---|
| $placeholder | string |
Returns: \RouteCollectionInterface
Sets the default controller to use when no other controller has been specified.
| Parameter Name | Type | Description |
|---|---|---|
| $value | ||
| $value |
Returns: \CodeIgniter\Router\RouteCollectionInterface
Sets the default method to call on the controller when no other method has been set in the route.
| Parameter Name | Type | Description |
|---|---|---|
| $value | ||
| $value |
Returns: \CodeIgniter\Router\RouteCollectionInterface
Sets the default namespace to use for Controllers when no other namespace has been specified.
| Parameter Name | Type | Description |
|---|---|---|
| $value | ||
| $value |
Returns: \CodeIgniter\Router\RouteCollectionInterface
Sets the current HTTP verb.
Used primarily for testing.
| Parameter Name | Type | Description |
|---|---|---|
| $verb | string |
Returns: $this
Tells the system whether to convert dashes in URI strings into underscores. In some search engines, including Google, dashes create more meaning and make it easier for the search engine to find words and meaning in the URI for better SEO. But it doesn't work well with PHP method names.
...
| Parameter Name | Type | Description |
|---|---|---|
| $value | bool |
Returns: \CodeIgniter\Router\RouteCollectionInterface
Returns the flag that tells whether to autoRoute URI against Controllers.
Returns: bool
Returns the current value of the translateURIDashes setting.
Returns: bool